<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" id="ipt">
  <div id="box"></div>
  <script>
    // const obj = {}
    // Object.defineProperty(obj, "val", {
      /* 6个参数：枚举、可读写、可修改、set、get、value */
    //   get () {
    //     console.log('get');
    //   },
    //   set (value) {
    //     console.log(value, 2233);
    //     console.log('set');
    //     document.querySelector('#box').innerHTML = value
    //   }
    // })
    // document.addEventListener('input', (e) => {
    //   console.log(e.target.value);
    //   obj.val = e.target.value
    // })
    /* es6 */
    const proxy = new Proxy({}, {
      get () {
        console.log('get');
      },
      set (target, property, value) {
        // console.log(target, property, value, 2233);
        console.log('set');
        document.querySelector('#box').innerHTML = value
      }
    })
    document.addEventListener('input', (e) => {
      proxy.value = e.target.value
    })
    // proxy.value=123
  </script>
</body>

</html>